package cate.game.role.show.msg;

import cate.common.rpc.path.RpcCommonPath;
import cate.game.GameBody;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdBBlog;
import cate.game.role.Role;
import cate.game.role.show.cmd.WatchBlogCmd;
import easy.java.dev.note.NoteField;
import easy.java.practice.errorcode.EcResult;

@ClientMsg(title = "查看其它玩家个人空间 の 请求")
public class OtherRoleBlogReq implements MsgInput {

    @NoteField("观察的玩家的uid")
    public String roleUid;

    @NoteField("玩家区服id")
    public int srvId;

    @Override
    public void execute(GameBody game, ClientContext cc) {
        EcResult r = settle(game, cc.getRole());
        game.notice.message(cc.getRole(), r, true);
    }

    private EcResult settle(GameBody game, Role role) {
        EcResult r = new EcResult();
		if (role.getBase().srvId == srvId) {
            Role otherRole = role.getGame().role.getRole(roleUid, true);
            if (otherRole != null) {
                role.sendNow(new OtherRoleBlogResp(otherRole));
                return r.success();
            }
        } else {
            WatchBlogCmd cmd = new WatchBlogCmd();
            cmd.srvId = srvId;
            cmd.roleId = roleUid;
            cmd = game.rpcSend().requestResponseGame(RpcCommonPath.WATCH_BLOG_G2G, srvId, cmd, WatchBlogCmd.class);
            if (cmd != null && cmd.data != null) {
                role.sendNow(cmd.data);
                return r.success();
            }
        }
        return r.fail("神秘人太高冷,不给查看");
    }

    private boolean isRobot() {
        return srvId <= 0;
    }

    @Override
    public MsgConfig conf() {
        return MsgIdBBlog.OTHER_ROLE_BLOG_REQ;
    }
}
